<?php
/* ******************************
 *	Request aJax actions
 * ******************************
*/

require_once('../includes/classes/core.php');
$action = $_REQUEST['act'];
$error	= '';
$data	= '';

switch ($action) {
	case 'logout':
		$page		= GetPage();
		$data		= array('page'	=> $page);
		
        break;
    case 'logout_save':   
        $tabel_id = $_REQUEST['tabel_id'];
        SaveLogout($tabel_id);
        break;
    default:
       $error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);


/* ******************************
 *	Request Functions
 * ******************************
 */

function SaveLogout($tabel_id)
{
    $user		= $_SESSION['USERID'];
    if($tabel_id == 1){
        mysql_query("
                     UPDATE  `worker_action` SET
                            `end_date`=NOW(),
                            `actived`='4'
                    WHERE   (`actived`= 4 or `actived`= 1) AND `person_id`='$user' AND date(start_date) = date(NOW())
                    ");
    }elseif($tabel_id == 2){
        mysql_query("
                    UPDATE  `worker_action` SET
                            `end_date`=NOW(),
                            `actived`='4'
                    WHERE   (`actived`= 4 or `actived`= 1) AND `person_id`='$user' AND date(start_date) = date(NOW())
                    ");
    }
}

function GetStatus()
{
    $data = '';
    $req = mysql_query("SELECT 	`id`, `name`
						FROM 	`tabel`
						WHERE 	actived=1");
    
        $data .= '<option value="0" selected="selected">----</option>';
    while( $res = mysql_fetch_assoc($req)){
        $data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';   
    }
    
    return $data;
}


function GetPage()
{
	$data  = '
	<div id="dialog-form">
		<fieldset style="margin-top: 5px;">
	       <select id="tabel_id">'.GetStatus().'</select>
	    </fieldset>	
    </div>';
    
	return $data;
}



?>
